from __future__ import annotations

from dataclasses import dataclass


@dataclass
class FallArrestRange:
    required_clearance_m: float
    lanyard_max_length_m: float
    note: str


def compute_fall_arrest_clearance(anchor_height_m: float, worker_height_m: float, lanyard_length_m: float, deceleration_m: float = 1.2, safety_margin_m: float = 1.0) -> FallArrestRange:
    """防坠落有效范围：所需净空 = 工器具长度+减速距离+安全裕度。"""

    clearance = worker_height_m + lanyard_length_m + deceleration_m + safety_margin_m
    return FallArrestRange(required_clearance_m=clearance, lanyard_max_length_m=max(0.5, anchor_height_m - clearance), note="净空不足需改用限制式保护")


